

clear
set more off
set logtype text
set matsize 800
cap log close
clear matrix




use "usa_00041.dta"   
global FE_LEVEL  "metarea"
global FE_NAME   "METRO"
global GENDER_SELECT  "sex==2"




log using prepare_women, replace
 

/* Download from IPUMS  ACS 3-YR 2011, 2000 5%, 1990 5% State, 1980 5% State, 1970 1% Metro fm1, 1970 Metro fm2, 1960 5%    */

  
keep   year  cpi99  statefip  metarea  gq  ownershp  ownershpd  valueh  perwt  nchild  nchlt5  sex  age  marst  bpl  racesing  school  educ  educd  gradeatt  gradeattd  schltype  empstat  empstatd  labforce  occ1990  ind1990  classwkr  classwkrd  wkswork1  wkswork2  hrswork1  hrswork2  uhrswork  absent  workedyr  incwage  incwelfr  incsupp  poverty  marst_mom  marst_pop  racesing_mom  racesing_pop 
 


replace year=2010 if  year==2011         

replace perwt = perwt/2  if year==1970   /* since there are two 1 percent samples for 1970  */

gen male   = sex==1
gen female = sex==2

gen white = racesing==1
gen black = racesing==2

gen immigrant =(bpl>=100)
gen native = immigrant==0




********************************************************************************************************************

keep if $GENDER_SELECT
keep if age>=25 & age<=55

********************************************************************************************************************



gen nevermar      =  marst==6
gen married_1     = (marst==1 | marst==2)                                      /* including spouse not present (marst==2)   */
gen divorced_1    = (marst==3 | marst==4)  if marst~=5 & marst~=6              /* separated or divorced among those ever married but not widowed  */
gen widowed_1     =  marst==5                                                  /* among all people               */
gen widowed_2     =  marst==5   if marst~=6                                    /* among those that were married  */

gen  selfemp =(classwkr==1)
gen  worked  = (wkswork2>=1 & wkswork2<=6)                                     /*  Worked more than zero weeks last year  */

egen hrswork_temp=mean(hrswork1),  by(hrswork2)
gen hrswork=uhrswork
replace hrswork=hrswork_temp if year==1970 | year==1960




gen  studying = school==2 if school~=.                                         
replace studying = 0  if gradeatt==0  &  year==1970  & school==.
replace studying = 1  if gradeatt~=0  &  year==1970  & school==.


rename ind1990  IND1990
rename occ1990  OCC1990

gen  manufacturing   = (IND1990>=100 & IND1990<400 & hrswork>=20)    if          studying~=1
gen blue_collar      = (OCC1990>500 & OCC1990<900  & hrswork>=20)    if          studying~=1
gen white_collar     = (OCC1990<500                & hrswork>=20)    if          studying~=1



gen service_industry=(IND1990==12 | IND1990==20 | IND1990==30 | (IND1990>=400 & IND1990<=432) | (IND1990>=440 & IND1990<=442) | ///
                     (IND1990>=450 & IND1990<=472) | IND1990==621| (IND1990>=700 & IND1990<=712) | (IND1990>=721 & IND1990<=760) | (IND1990>=761 & IND1990<=791) | ///
                     (IND1990>=800 & IND1990<=810) | (IND1990>=812 & IND1990<=893) ) & hrswork>=20
gen  services  =  service_industry   if           studying~=1 



 
* OCCUPATION GROUPS


gen     occ_group = 1  if   OCC1990<=22 					/*  Executive, Administrative, and Managerial Occupations*/
replace occ_group = 2  if   OCC1990>22  & OCC1990<=37		/*  Management Related Occupations*/
replace occ_group = 3  if   OCC1990>43  & OCC1990<=59		/*  Engineers, Architechts, and Surveyors*/
replace occ_group = 4  if   OCC1990>59  & OCC1990<=68		/*  Mathematical and Computer Scientists*/
replace occ_group = 5  if   OCC1990>68  & OCC1990<=83		/*  Natural Scientists*/
replace occ_group = 6  if   OCC1990>83  & OCC1990<=89 		/*  Health Diagnosing Occupations*/
replace occ_group = 7  if   OCC1990>89  & OCC1990<=97		/*  Health Assessment and Treating Occupations*/
replace occ_group = 8  if   OCC1990>97  & OCC1990<=106		/*  Therapists*/
replace occ_group = 9  if   OCC1990>106 & OCC1990<=154	    /*  Teachers, Postsecondary*/
replace occ_group = 10 if   OCC1990>154 & OCC1990<=163	    /*  Teachers, Except Postsecondary*/
replace occ_group = 11 if   OCC1990>163 & OCC1990<=165	    /*  Librarians, Archivists, and Curators*/
replace occ_group = 12 if   OCC1990>165 & OCC1990<=173  	/*  Social Scientists and Urban Planners*/
replace occ_group = 13 if   OCC1990>173 & OCC1990<=176 	    /*  Social, Recreation, and Religious Workers*/
replace occ_group = 14 if   OCC1990>176 & OCC1990<=179	    /*  Lawyers and Judges*/
replace occ_group = 15 if   OCC1990>179 & OCC1990<=200	    /*  Writers, Artists, Entertainers, and Athletes*/
replace occ_group = 16 if   OCC1990>200 & OCC1990<=208	    /*  Health Technologists and Technicians*/
replace occ_group = 17 if   OCC1990>208 & OCC1990<=223	    /*  Engineering and Related Technologists and Technicians*/
replace occ_group = 18 if   OCC1990>223 & OCC1990<=235	    /*  Technicians, Except Health, Engineering, and Science*/
replace occ_group = 19 if   OCC1990>235 & OCC1990<=303 	    /*  Sales Occupations*/
replace occ_group = 20 if   OCC1990>303 & OCC1990<=315	    /*  Computer Equipment Operators*/
replace occ_group = 21 if   OCC1990>315 & OCC1990<=344	    /*  Information Clerks*/
replace occ_group = 22 if   OCC1990>344 & OCC1990<=347	    /*  Duplicating, Mail, and Other Office Machine Operators*/
replace occ_group = 23 if   OCC1990>347 & OCC1990<=357      /*  Communications Equipment Operators*/
replace occ_group = 24 if   OCC1990>357 & OCC1990<=373	    /*  Material Recording, Scheduling, and Distributing Clerks*/
replace occ_group = 25 if   OCC1990>373 & OCC1990<=389	    /*  Adjusters and Investigators*/
replace occ_group = 26 if   OCC1990>389 & OCC1990<=469	    /*  SERVICE OCCUPATIONS*/
replace occ_group = 27 if   OCC1990>469 & OCC1990<=498 	    /*  FARMING, FORESTRY, AND FISHING OCCUPATIONS*/
replace occ_group = 28 if   OCC1990>498 & OCC1990<=699	    /*  PRECISION PRODUCTION, CRAFT, AND REPAIR OCCUPATIONS*/
replace occ_group = 29 if   OCC1990>699 & OCC1990<=889	    /*	OPERATORS, FABRICATORS, AND LABORERS*/
replace occ_group = 30 if   OCC1990>889 & OCC1990<=905	    /*  MILITARY OCCUPATIONS*/




 

* INDUSTRY GROUPS

gen     ind_group = 1   if    IND1990>=10 & IND1990<=32 		/*  AGRICULTURE, FORESTRY, AND FISHERIES*/
replace ind_group = 2   if    IND1990>32  & IND1990<=50 		/*	MINING*/
replace ind_group = 3   if    IND1990>50  & IND1990<=60      	/*	CONSTRUCTION*/
replace ind_group = 4   if    IND1990>60  & IND1990<=392		/*  MANUFACTURING*/
replace ind_group = 5   if    IND1990>392 & IND1990<=472		/*	TRANSPORTATION, COMMUNICATIONS, AND OTHER PUBLIC UTILITIES*/
replace ind_group = 6   if    IND1990>472 & IND1990<=571		/*	WHOLESALE TRADE*/
replace ind_group = 7   if    IND1990>571 & IND1990<=691		/*	RETAIL TRADE*/
replace ind_group = 8   if    IND1990>691 & IND1990<=712		/*	FINANCE, INSURANCE, AND REAL ESTATE*/
replace ind_group = 9   if    IND1990>712 & IND1990<=760		/*	BUSINESS AND REPAIR SERVICES*/
replace ind_group = 10  if    IND1990>760 & IND1990<=791		/*	PERSONAL SERVICES*/
replace ind_group = 11  if    IND1990>791 & IND1990<=810		/*	ENTERTAINMENT AND RECREATION SERVICES*/
replace ind_group = 12  if    IND1990>810 & IND1990<=893		/*	PROFESSIONAL AND RELATED SERVICES*/
replace ind_group = 13  if    IND1990>893 & IND1990<=932		/*	PUBLIC ADMINISTRATION*/




*************************************************
*  Industries within MFG for the Bartik MFG IV
*************************************************
gen  industry_temp="."
replace industry_temp="Nondurable Goods" 									 if   IND1990>=100 & IND1990<=130		/*  Nondurable Goods*/
replace industry_temp="Textile mill products" 								 if   IND1990>=132 & IND1990<=150		/*  Textile mill products*/
replace industry_temp="Apparel and other finished textile products" 		 if   IND1990>=151 & IND1990<=152 		/*	Apparel and other finished textile products*/
replace industry_temp="Paper and allied products" 							 if   IND1990>=160 & IND1990<=162 		/*	Paper and allied products*/
replace industry_temp="Printing, publishing, and allied industries" 		 if   IND1990>=171 & IND1990<=172 		/*	Printing, publishing, and allied industries*/
replace industry_temp="Chemicals and allied products" 						 if   IND1990>=180 & IND1990<=192 		/*	Chemicals and allied products*/
replace industry_temp="Petroleum and coal products"							 if   IND1990>=200 & IND1990<=201		/*	Petroleum and coal products*/
replace industry_temp="Rubber and miscellaneous plastics products"			 if   IND1990>=210 & IND1990<=212 	    /*	Rubber and miscellaneous plastics products*/
replace industry_temp="Leather and leather products"						 if   IND1990>=220 & IND1990<=222 	    /*	Leather and leather products*/
replace industry_temp="Lumber and woods products, except furniture" 		 if   IND1990>230  & IND1990<=242		/*  Lumber and woods products, except furniture*/
replace industry_temp="Stone, clay, glass and concrete products"			 if   IND1990>=250 & IND1990<=262		/*	Stone, clay, glass and concrete products*/
replace industry_temp="Metal industries" 									 if   IND1990>=270 & IND1990<=301		/*	Metal industries*/
replace industry_temp="Machinery and computing equipment"					 if   IND1990>=310 & IND1990<=332		/*	Machinery and computing equipment*/
replace industry_temp="Electrical machinery, equipment, and supplies" 		 if   IND1990>340  & IND1990<=350		/*	Electrical machinery, equipment, and supplies*/
replace industry_temp="Transportation equipment" 							 if   IND1990>351  & IND1990<=370		/*	Transportation equipment*/
replace industry_temp="Professional and photographic equipment, and watches" if   IND1990>371  & IND1990<=392		/*	Professional and photographic equipment, and watches*/
encode industry_temp, generate (industry)
bysort year:  tab industry, missing







*  Replacing top coding

replace incwage = .  if incwage== 999999     /*  N/A        */
replace incwage = .  if incwage== 999998     /*  missing    */
 
replace incwage=incwage*1.5  if year==1960 & incwage==25000
replace incwage=incwage*1.5  if year==1970 & incwage==50000
replace incwage=incwage*1.5  if year==1980 & incwage==75000
replace incwage = incwage*cpi99
gen lincwage = log(incwage)  if incwage~=. & incwage~=0

 

replace valueh = . if valueh==0 | valueh==9999998 | valueh==9999999
replace valueh=valueh*1.5  if year==1960 & valueh==35000
replace valueh=valueh*1.5  if year==1970 & valueh==50000
replace valueh=valueh*1.5  if year==1980 & valueh==200000
replace valueh=valueh*1.5  if year==1990 & valueh==400000
replace valueh=valueh*1.5  if year==2000 & valueh==1000000   
replace valueh=valueh*cpi99
gen lvalueh = log(valueh) if valueh~=0


gen home_owner = ownershp==1



gen       welfare_inc    =  incwelfr                if year>=1970   
replace   welfare_inc    =  incwelfr + incsupp      if year>=2000    
gen       welfare_dummy  =  welfare_inc > 0         if year>=1970
drop      incwelfr  incsupp

gen poor  =  poverty<=100  if poverty~=0 

drop ownershp  poverty  


gen     educ_n=.
replace educ_n= . if educ==0
replace educ_n=2  if educ==1
replace educ_n=7  if educ==2
replace educ_n=9  if educ==3
replace educ_n=10 if educ==4
replace educ_n=11 if educ==5
replace educ_n=12 if educ==6
replace educ_n=13 if educ==7
replace educ_n=14 if educ==8
replace educ_n=15 if educ==9
replace educ_n=16 if educ==10
replace educ_n=18.5 if educ==11

gen age_25_34=(age>=25 & age<=34) 
gen age_35_44=(age>=35 & age<=44) 
gen age_45_55=(age>=45 & age<=55) 

gen HSD=(educ_n<12) 
gen HSG=(educ_n==12)
gen COD= (educ_n>12 & educ_n<16)
gen COG=(educ_n>=16)
gen NONCOG=(educ_n<16)

gen     educ_group = 1  if  HSD==1
replace educ_group = 2  if  HSG==1
replace educ_group = 3  if  COD==1
replace educ_group = 4  if  COG==1


gen     age_group = 1  if  (age>=25 & age<30)
replace age_group = 2  if  (age>=30 & age<35)
replace age_group = 3  if  (age>=35 & age<40)
replace age_group = 4  if  (age>=40 & age<45)
replace age_group = 5  if  (age>=45 & age<50)


gen emprate            = (hrswork>=30)   |  studying==1                         if             gq==1  
gen emprate_noncog     = (hrswork>=30)   |  studying==1                         if NONCOG==1 & gq==1  
gen emprate_cog        = (hrswork>=30)   |  studying==1                         if COG==1    & gq==1  




*********************************************************************************************************************************************************************

drop if empstatd==14                   /* Dropping those Armed forces--at work*/



replace nevermar     = .  if native==0
replace married_1    = .  if native==0  
replace divorced_1   = .  if native==0  
gen married_2        =  married_1   if native==1  &  gq==1
gen divorced_2       =  divorced_1  if native==1  &  gq==1

replace widowed_1    = .  if native==0
replace widowed_2    = .  if native==0

gen single_mom           =  marst~=1 & nchild>0          if sex==2

gen  mfg = manufacturing                                 if native==1
replace  services   = .  if immigrant==1


replace  immigrant  =  . if gq~=1
replace  welfare_dummy   = .                             if native==0
replace  home_owner      = .                             if native==0
gen       groupq         =    gq~=1                      if native==1    

replace  lvalueh =  .  if   immigrant==1
replace poor     =  .  if   immigrant==1





replace HSD = .  if  immigrant==1 
replace HSG = .  if  immigrant==1 
replace COD = .  if  immigrant==1 
replace COG = .  if  immigrant==1 

replace age_25_34 = .  if  immigrant==1 
replace age_35_44 = .  if  immigrant==1 
replace age_45_55 = .  if  immigrant==1 

replace emprate            = .  if immigrant==1
replace emprate_noncog     = .  if immigrant==1
replace emprate_cog        = .  if immigrant==1




sum incwage, det
replace lincwage =  .  if native==0 | wkswork2~=6 | hrswork<35  | gq~=1  | studying==1  | selfemp==1  /* native, working 50-52 weeks, at least 35 hrs per week, not in group quarters, not a student or self-employed */
sum lincwage, det
replace lincwage = .  if incwage<4160                                                                 /*  less than two dollars an hour for 40 hrs a week and 52 weeks, min wage was 5.15 in 1999  */
sum lincwage, det



global  VARBLIST          "married_1  married_2  nevermar  divorced_1   widowed_2    poor  welfare_dummy  home_owner    groupq    emprate     emprate_noncog   emprate_cog    lincwage  lvalueh"
global  VARBLIST_FEMALES  "single_mom    "
global  VARB_DEMOS        "mfg   services       HSD HSG COD COG  educ_n  age_25_34  age_35_44  age_45_55"
global  SPEC_1            "HSD HSG COD COG age_25_34 age_35_44 age_45_55 i.year"





**********************************************************************************************************************************************************************************************************************





******************************
***  FIGURES FOR WOMEN     ***
******************************

preserve

keep if sex==2
keep if age<=45
keep if native==1
drop if black==0 & white==0


global  WOMEN_FIG_LIST   "   lincwage  emprate  welfare_dummy nevermar  divorced_1  widowed_2   home_owner  lvalueh  poor  single_mom"

foreach varb1 in $WOMEN_FIG_LIST  {
gen      blackfem_`varb1' = `varb1'   if racesing==2
gen      whitefem_`varb1' = `varb1'   if racesing==1
}

collapse    blackfem_*  whitefem_*   $WOMEN_FIG_LIST      [aw=perwt], by(year)

format   whitefem_poor  blackfem_poor  whitefem_nevermar  blackfem_nevermar   whitefem_single_mom   blackfem_single_mom    %9.3f

global FIG_NUMBER "A2"
twoway       (connected whitefem_single_mom year, mlabel(whitefem_single_mom) mlabsize(small) mlabp(6 6))     (connected blackfem_single_mom year, lpattern(dash)  msymbol(triangle)  mlabel(blackfem_single_mom) mlabsize(small) mlabp(6 6)),   ///
title("Figure ${FIG_NUMBER}: Percent Women who are Single Mothers" , size(medlarge))  subtitle("Females - 25-45 Years Old",size(medsmall))                             ///
xtitle("Year")     xscale(range(1960 2015))   ///
legend(region(lstyle(none)) label(1 White Women) label(2 Black Women )  )  ///
caption("Notes: The sample includes native born women between the ages of 25 and 45."  , size(vsmall)) ///
ytitle("Percent Single Mothers", size(small))  ylabel(0(0.1)0.5) ylabel(,labsize(small) format(%9.2f)) 
graph save Graph  Figure_${FIG_NUMBER}, replace
restore





********************************************
*  GENERATE MAIN VARBS FOR BLACK FEMALES   *
********************************************

preserve
keep if age<=45
keep if sex==2
keep if racesing==2
keep if native==1
drop if $FE_LEVEL==0


foreach varb1 in $VARBLIST  $VARBLIST_FEMALES  $VARB_DEMOS  {
rename  `varb1'  blackfem_`varb1'
}
collapse  blackfem_*  [aw=perwt] , by($FE_LEVEL  year)
bysort year:  sum
sort $FE_LEVEL  year
save ${FE_NAME}_black_females_mainvarbs, replace
restore





********************************************
*  GENERATE MAIN VARBS FOR WHITE FEMALES   *
********************************************

preserve
keep if age<=45
keep if sex==2
keep if racesing==1
keep if native==1
drop if $FE_LEVEL==0

foreach varb1 in $VARBLIST  $VARBLIST_FEMALES  $VARB_DEMOS  {
rename  `varb1'  fem_`varb1'
}

collapse  fem_*  [aw=perwt] , by($FE_LEVEL  year)
bysort year:  sum
sort $FE_LEVEL  year
save ${FE_NAME}_females_mainvarbs, replace

restore



****************************************************************************
*   WOMEN  ---  BLACK WHITE GAP, ROR TO COLLEGE FOR WHITES AND BLACKS      *
****************************************************************************

keep if age<=45

keep if sex==2
keep if native==1


drop if $FE_LEVEL==0
drop if black==0 & white==0

gen x_1 = emprate  if black==1
egen  black_nobs=count(x_1), by($FE_LEVEL  year)
drop if black_nobs<30
drop x_1 black_nobs


global  VARB_GAPX_FEM         "           single_mom  nevermar  divorced_1  widowed_2  emprate    lvalueh  groupq   poor  welfare_dummy   "

foreach  varb1  in  $VARB_GAPX_FEM  {
gen           femgapx_`varb1' = .
gen           fem_ror_`varb1' = .
gen      blackfem_ror_`varb1' = .
}


foreach DECADE of numlist 1960 1970 1980 1990 2000 2010  {
di "hello world"
preserve
keep if year==`DECADE'
levelsof $FE_LEVEL, local(levels)
foreach GEO in  `levels' {

foreach  varb1  in  $VARB_GAPX_FEM  {
cap noi   regress  `varb1'          educ_n  age  i.age_group           [aw=perwt]             if    $FE_LEVEL==`GEO' & year==`DECADE'  & white==1
cap noi   replace               fem_ror_`varb1' =  _b[educ_n]                                 if    $FE_LEVEL==`GEO' & year==`DECADE'  & white==1 
ereturn clear                                                   
cap noi   regress  `varb1'          educ_n  age  i.age_group           [aw=perwt]             if    $FE_LEVEL==`GEO' & year==`DECADE'  & black==1
cap noi   replace          blackfem_ror_`varb1' =  _b[educ_n]                                 if    $FE_LEVEL==`GEO' & year==`DECADE'  & black==1 
ereturn clear                                                   
}

foreach  varb1  in  $VARB_GAPX_FEM  {
cap noi   regress `varb1'           HSD COD COG  age  i.age_group   black   [aw=perwt]        if    $FE_LEVEL==`GEO' & year==`DECADE'
cap noi   replace                   femgapx_`varb1' =  _b[black]                              if    $FE_LEVEL==`GEO' & year==`DECADE'
ereturn clear                                                   
}
}
keep  $FE_LEVEL  year  femgapx_*  blackfem_ror_*  fem_ror_*
collapse               femgapx_*  blackfem_ror_*  fem_ror_* , by($FE_LEVEL year)
sort  $FE_LEVEL  year
save  SCRAP_ROR_`DECADE' , replace
restore
}

bysort year: sum age lincwage  COG

clear
use  SCRAP_ROR_1960
merge  $FE_LEVEL  year   using SCRAP_ROR_1970  SCRAP_ROR_1980  SCRAP_ROR_1990  SCRAP_ROR_2000  SCRAP_ROR_2010
tab  _merge
drop _merge
sort  $FE_LEVEL  year
save ${FE_NAME}_ROR_gapx_fem, replace
 


 